package com.suiwei;

import com.suiwei.base.config.User;
import com.suiwei.base.controller.BookController;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
//可以将使用@ConfigurationProperties注解对应的类加入spring容器，以便统一管理
//如果不使用该注解的话，@ConfigurationProperties注解的类要加上@Component
@EnableConfigurationProperties({User.class})
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        //args为启动项目时，外部输入的参数
        //System.out.println(Arrays.toString(args));
        //可以在启动程序时候，不读取args，那么外部就无法干预启动参数了
        //SpringApplication.run(Application.class)
        //ctx就是容器对象,spring的容器，run方法就是启动初始化了一个spring容器
        //扫描启动类所在包，并加载bean。外面的bean不加载，所以启动类必须在项目的最外层
        ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
        //容器中有很多bean，从容器中拿出bean
        BookController bean = ctx.getBean(BookController.class);
        //System.out.println(bean);
    }
    /**
     * 向spring容器中初始注入scheduler
     */
    @Bean
    public Scheduler scheduler() throws SchedulerException {
        SchedulerFactory factory = new StdSchedulerFactory();
        return factory.getScheduler();
    }

}
